'use strict';

const Controller = require('egg').Controller;
let students = [
  {
    id: 1,
    name: "小王",
    grade: "100"
  },
  {
    id: 2,
    name: "小汪",
    grade: "98"
  },
  {
    id: 3,
    name: "小旺",
    grade: "60"
  },
  {
    id: 4,
    name: "小往",
    grade: "100"
  },
  {
    id: 5,
    name: "小魍",
    grade: "99"
  },
]
class StudentController extends Controller {
  async index() {
    this.ctx.body = students
  }
  // post请求
  async create() {
    const list = this.ctx.request.body.list;
    students.push(list);
    this.ctx.body = "添加成功！"
  }
  // /fruits/:id delete请求
  async destroy() {
    let id = this.ctx.params.id;
    students.splice(id, 1);
    this.ctx.body = "删除成功！"
  }
}

module.exports = StudentController